package com.yjhb.android.sbz.dialog;

import android.app.Activity;
import android.graphics.Color;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatRadioButton;

import com.yjhb.android.sbz.R;
import com.jojo.android.zxlib.base.BaseDialog;
import com.jojo.android.zxlib.interfaces.Callback;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者 zx
 * 创建时间 2021/1/14 11:17
 */
public class ClockRegisterDialog extends BaseDialog {
    private final String TAG = "ClockRegisterDialog";
    @BindView(R.id.single_tv)
    TextView singleTv;
    @BindView(R.id.double_tv)
    TextView doubleTv;
    @BindView(R.id.radio_1)
    AppCompatRadioButton radio1;
    @BindView(R.id.radio_2)
    AppCompatRadioButton radio2;
    @BindView(R.id.rg_num)
    RadioGroup rgNum;

    TextView currentSelected;

    Callback<Map<String, Object>> callback;

    public ClockRegisterDialog(Activity context, Callback<Map<String, Object>> callback) {
        super(context);
        this.callback = callback;
    }

    @Override
    protected void init() {
        currentSelected = doubleTv;
        selected(singleTv);
    }


    @OnClick({R.id.single_tv, R.id.double_tv})
    void selected(TextView textView) {
        currentSelected.setTextColor(Color.BLACK);
        currentSelected.setBackgroundColor(Color.WHITE);
        currentSelected = textView;
        currentSelected.setTextColor(Color.WHITE);
        currentSelected.setBackgroundColor(activity.getResources().getColor(R.color.blue_f8));
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_clock_register;
    }

    @OnClick({R.id.close_iv, R.id.cancel_tv})
    void close() {
        dismiss();
    }

    @OnClick(R.id.ok_tv)
    void onSubmit() {
        if (callback != null) {
            Map<String, Object> map = new HashMap<>();
            map.put("payType", radio1.isChecked() ? 1 : 2);
            map.put("money", new BigDecimal(currentSelected == singleTv ? "1" : "2"));
            callback.callback(map);
        }
        dismiss();
    }
}
